% TEST_ID: LANG-EXPAND-0080
% CATEGORY: stdlib/arithmetic_ops/bitops
% 测试 bitset 函数
function test_bit_bitset()
A = 4;
intout = bitset(A,4:6);
result = [12    20    36];
assert_istrue(intout, result);
assert(isa(result, 'double'));

intout = bitset(75,5,'int8');
result = 91;
assert_istrue(intout, result);
assert(isa(result, 'double'));

a = intmax('uint8');
for k = 0:7
   a = bitset(a, 8-k, 0);
   b(1,k+1) = a;
end
b
assert_istrue(b, [ 127    63    31    15     7     3     1     0]);

bits = 2:6;
val = [1 0 0 1 1];
intout = bitset(0, bits,val,'int8');
result = [2     0     0    16    32];
assert_istrue(intout, result);

a = int32(1);
result = bitset(a, 1, 0);
assert_istrue(result, 0);
assert(isa(result, 'int32'));

assert_istrue(bitset(int64(0), 64, 1), intmin('int64'));

end

function assert_istrue(x, y)
    assert(isequal(x, y));
end